<?php
/**
 * pemilu
 * copyright (c) 2013 abie
 *
 * @author abie
 * @date 12/20/13 12:51 AM
 */

class Pemilihan extends MyModel {
    private static $model = null;

    private static $data = array(
        20 => array(
            'judul' => 'Pemilihan Presiden dan Wakil Presiden',
            'type' => 'presiden',
        ),

        10 => array(
            'judul' => 'DPRD Tingkat 2',
            'type' => 'legislatif',
        ),

        11 => array(
            'judul' => 'DPRD Tingkat 1',
            'type' => 'legislatif',
        ),

        12 => array(
            'judul' => 'DPD',
            'type' => 'legislatif',
        ),

        13 => array(
            'judul' => 'DPD',
            'type' => 'legislatif',
        ),
    );

    private $id, $judul, $type;

    public static function model() {
        if (self::$model == null) {
            self::$model = new Pemilihan();
        }
        return self::$model;
    }


    public function findByPk($id) {
        $data = self::$data[$id];
        $className = 'Pemilihan' . ucfirst($data['type']);
        $pemilihan = new $className();
        $pemilihan->id = $id;
        $pemilihan->judul = $data['judul'];
        $pemilihan->type = $data['type'];
        return $pemilihan;
    }

    /**
     * Returns the list of attribute names of the model.
     *
     * @return array list of attribute names.
     */
    public function attributeNames()
    {
        return array('judul', 'calon');
    }

    /**
     * @return string[]
     */
    protected function getAllKeys()
    {
        return array_keys(self::$data);
    }

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @return mixed
     */
    public function getJudul()
    {
        return $this->judul;
    }

    /**
     * @return mixed
     */
    public function getType()
    {
        return $this->type;
    }

    public function getCalon() {
        return Calon::model()->findAll(array('pemilihan' => $this->id));
    }


}